package org.gw.building.repositories;

import org.gw.building.model.CourseInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.Date;

public interface CourseInfoRepository extends CrudRepository<CourseInfo, String> {

	@Query("from CourseInfo t where (?1 is null or t.kclb=?1) and (?2 is null or t.term.id=?2) and (?3 is null or t.name like ?3) and (?4 is null or t.zjr like ?4) and (?5 is null or t.zbdw like ?5) order by t.fbsj desc")
	public Page<CourseInfo> query(String type, String term, String name, String zjr, String zbdw, Pageable pageable);

	@Query("from CourseInfo c where c.name=?1 and c.term.id = ?2")
	public CourseInfo findOneByNameAndTerm(String name, String term);

	@Query("from CourseInfo t where (?1 is null or t.kclb=?1) and (?2 is null or t.term.id=?2) and (?3 is null or t.name like ?3) and (?4 is null or t.zjr like ?4) and (?5 is null or t.zbdw like ?5) "
			+ "and (?6 is null or t.name like ?6 or t.kcjj like ?6 or t.zjr like ?6) and (?7 is null or t.fbsj<?7) order by t.fbsj desc")
	public Page<CourseInfo> query(String type, String term, String name, String zjr, String zbdw, String fuzzyName, Date fbsj, Pageable pageable);
}
